feat(fastapi): add APP_URL support to FastAPIConfig#111
Conversation
❌ Code Review: CHANGES REQUESTED — 6 tests failCritical: Tests test the wrong layerThe PR moves host/port/URL resolution logic from (The PR description says "All 15 tests pass" — this is incorrect.) Issue 1 —
|
…ivation Parse APP_URL (e.g. http://myapp.com:8080 or https://production.example.com) to derive default host and port. Priority order: APP_HOST/APP_PORT env vars win, then APP_URL hostname/port, then hard-coded defaults (127.0.0.1/8000). Adds 15 tests covering all resolution scenarios. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace three-function APP_URL parsing helpers with a single _parse_app_url(component) helper and inline or-chain lambdas in the dataclass fields. Remove all importlib.reload() calls from the test suite — monkeypatch works directly since default_factory lambdas call env() at instantiation time. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…o ServeCommand FastAPIConfig now stores only raw env values (APP_HOST, APP_PORT, APP_URL) with no parsing logic or hardcoded defaults. _resolve_host_port() in ServeCommand owns the full APP_HOST/APP_PORT → APP_URL → 127.0.0.1/8000 resolution chain, making the priority order explicit and testable in isolation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…priority Replace urllib.parse.urlparse with Uri.of() from fastapi_startkit.support. Extend _resolve_host_port() to accept CLI args as top-priority parameters, enforcing strict: CLI flag → APP_HOST/APP_PORT → APP_URL → hardcoded default. Rewrite tests to target _resolve_host_port() directly and cover the full priority chain including CLI overrides; update FastAPIConfig tests to reflect that the config dataclass stores raw env values only (no defaults or parsing). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ecccaaa to
d2223e5
Compare
… _resolve_host_port Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
APP_URLenv var support toFastAPIConfigso host and port can be derived from a full URL (e.g.http://myapp.com:8080orhttps://production.example.com)_parse_app_url(),_default_host(), and_default_port()helper functions with clear priority rules127.0.0.1/8000)myapp.com:9000) are handled by prependinghttp://before parsingChanges
fastapi_startkit/src/fastapi_startkit/fastapi/config/fastapi.py— rewiredhost/portfields to use new helper functions; addedurllib.parseandosimportsfastapi_startkit/tests/fastapi/test_fastapi_config.py— 15 new tests across 4 test classes covering all resolution scenariosTest plan
host="127.0.0.1",port=8000APP_HOST+APP_PORTset → those values usedAPP_URL=http://myapp.com:9000→host="myapp.com",port=9000APP_URL=https://production.example.com→host="production.example.com",port=8000(no port in URL)APP_URL=http://myapp.com:9000+APP_HOST=override.com→APP_HOSTwins:"override.com"APP_URL=myapp.com:9000(no scheme) →host="myapp.com",port=9000uv run pytest tests/fastapi/test_fastapi_config.py -v🤖 Generated with Claude Code